package com.karl.mytask_2.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.TextView;

import com.karl.mytask_2.R;
import com.karl.mytask_2.adapter.UserAdapter;
import com.karl.mytask_2.tools.ActivityCollector;
import com.karl.mytask_2.tools.BaseActivity;
import com.karl.mytask_2.tools.BaseFragmentActivity;
import com.karl.mytask_2.tools.FragmentActivityCollector;

import cn.bmob.v3.BmobUser;

/**
 * Created by Karl on 2016/5/21.
 */
public class SettingsActivity extends BaseActivity implements View.OnClickListener {
    private TextView mToolBarTitle;
    private ImageButton mBack;

    private RecyclerView mRecycler;
    private UserAdapter mAdapter;
    private int[] mListImg = new int[]{
            R.mipmap.setting_about_app,
            R.mipmap.setting_question,
            R.mipmap.setting_update,
            R.mipmap.setting_logout};
    private String[] mListName = new String[]{
            "关于软件",
            "问题反馈",
            "更新密码",
            "退出登录"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.settings);
        initView();
        initEvent();
    }
    private void initView(){
        mToolBarTitle = (TextView) findViewById(R.id.tool_bar2_title);
        mBack = (ImageButton) findViewById(R.id.tool_bar2_back);
        mRecycler = (RecyclerView) findViewById(R.id.user_recycler_view);



    }
    private void initEvent(){
        mToolBarTitle.setText("设置中心");
        mBack.setOnClickListener(this);
        mRecycler.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));
        mAdapter = new UserAdapter(mListName,mListImg);
        mRecycler.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new UserAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, String data) {
                switch (data){
                    case "关于软件":
                        break;
                    case "问题反馈":
                        break;
                    case "更新密码":{
                        startActivity(new Intent().setClass(SettingsActivity.this,UpdatePasswordActivity.class));

                    }
                        break;
                    case "退出登录": {
                        //退出登陆操作
                        BmobUser.logOut(getApplicationContext());
                        BmobUser user = BmobUser.getCurrentUser(getApplicationContext());
                        startActivity(new Intent().setClass(SettingsActivity.this, LoginActivity.class));
                        //需要补充的是关闭之前所有的Activity
                        ActivityCollector.finishAll();
                        FragmentActivityCollector.finishAll();

                    }
                        break;
                    default:
                        break;

                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tool_bar2_back:
                SettingsActivity.this.finish();
                break;
            default:
                break;
        }
    }
}
